<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'pages-add', //页面标示
    'pagename' => '添加页面片', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
   'footerjs'=>array('content/fuelux/fuelux','content/combodate/moment.min','content/combodate/combodate','content/calendar'),
    'head' => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<section id="content">
  <section class="main padder">
    <div class="clearfix">
      <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'],'_');?></h4>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <section class="panel">
          <div class="panel-body">
            <form class="form-horizontal" method="post" id="form1">
              <div class="form-group">
                <label class="col-sm-1 control-label">页面片名称</label>
                <div class="col-sm-3">
                  <input type="text" name="title" id="title" placeholder="" class="form-control" value="" />
                  <span class="help-block">标题不能长于40个字符</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">排序</label>
                <div class="col-sm-3">
                  <input type="text" name="sort" id="sort" placeholder="" class="form-control" value="0" />
                  <span class="help-block">页面片排序，数字越大越靠前</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">文件上传入口</label>
                <div class="col-sm-3">
                  <iframe width="280" height="24" src="<?php echo U('upload/index',array('id'=>'upload_url','ids'=>'uploadCallBack')); ?>" scrolling="no" frameborder="0"></iframe>
                </div>
              </div>
 			<div class="form-group" id="show-upload-url" style="display:none">
                <label class="col-sm-1 control-label">上传路径</label>
                <div class="col-sm-6">
                  <input type="text" name="img_url" id="img_url" placeholder="" class="form-control" value="" />
                  <input type="hidden" name="upload_url" id="upload_url" placeholder="" class="form-control" value="" />
                  <span class="help-block">请将完整路径添加到页面片中</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">页面代码</label>
                <div class="col-sm-6">
                  <textarea class="form-control" id="content" name="content"  style="height:380px"></textarea>
                  <span class="help-block">请直接粘贴HTML代码片段</span></div>
              </div>
              <div class="form-group">
                <div class="col-sm-9 col-lg-offset-1">
                  <div class="col-sm-1">
                    <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                  </div>
                  <div class="col-md-offset-2">
                    <button type="button" class="btn btn-white">取消</button>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </section>
      </div>
    </div>
  </section>
</section>
<!--主体 结束--> 
<link rel="stylesheet" media="screen" href="<?php echo PUBLIC_PATH; ?>jquery-ui/css/smoothness/jquery-ui-1.10.0.custom.min.css"/>
<script type="text/javascript" src="<?php echo PUBLIC_PATH; ?>jquery-ui/js/jquery-ui-1.10.0.custom.min.js"></script>
<script type="text/javascript" src="<?php echo PUBLIC_PATH; ?>jquery-ui/js/jquery-ui-timepicker-addon.js"></script>
<script>
function uploadCallBack(arr){
	console.log(arr);
	$("#img_url").val(arr.file_url);
	$("#show-upload-url").show();
}
$(function(){
	$('#form1').submit(function(){
		var title=$.trim($("#title").val());
		var isOk=true;
		if (!title){
			Msg.error('名称不能为空');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		Msg.loading();
		  $.post('<?php echo U('pages/post');?>',$(this).serialize(),function(result){
			  Msg.hide();
			  resetSubmit("#sub-ok",'保存');
			  if (result.status==1){
				Msg.ok('添加成功',function(){
					document.location='<?php echo U('pages/index');?>';	
				},1000);  
			}else{
				Msg.error(result.info);
			}
		  },'json');
		  return false;
	});
})
</script>
<?php
include getTpl('footer', 'public');
?>